package com.braveman.im.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ht.baselibs.utils.DeviceUtils;
import com.braveman.im.R;

public class TipsDialog extends Dialog implements OnClickListener {

    private TextView mOkButton;
    private TextView mCancelButton;

    private OnDialogTipsClickListener mListener;
    private String name;
    private Uri uri;
    private String title;
    private String content;
    private String content1;
    private String congtent2;
    private TextView mTitleView;
    private TextView mContentView1;
    private TextView mContentView2;
    private TextView mContentView;
    private String leftBtnText;
    private String rightBtnText;
    private LinearLayout mLLContent1;
    private LinearLayout mLLContent;
    private TextView mTvTitleHint1;
    private String titileHint;
    private String titileHint2;
    private TextView mTvTitleHint2;

    public TipsDialog(Context context) {
        super(context, R.style.albumDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_ios_tip);
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.alpha = 1.0f;
        this.getWindow().setWindowAnimations(R.style.Dialog_Fade);
        this.getWindow().setAttributes(lp);
        this.getWindow().setLayout(DeviceUtils.getScreenWidth(getContext()), DeviceUtils.getScreenHeight(getContext()));


        mTitleView = (TextView) findViewById(R.id.tv_dialog_tip_title);
        mContentView1 = (TextView) findViewById(R.id.tv_dialog_tip_content1);
        mContentView2 = (TextView) findViewById(R.id.tv_dialog_tip_content2);
        mContentView = (TextView) findViewById(R.id.tv_dialog_tip_content);
        mLLContent = (LinearLayout) findViewById(R.id.ll_dialog_tip_content);
        mLLContent1 = (LinearLayout) findViewById(R.id.ll_dialog_tip_content1);
        mTvTitleHint1 = (TextView) findViewById(R.id.tv_dialog_tip_title_hint1);
        mTvTitleHint2 = (TextView) findViewById(R.id.tv_dialog_tip_title_hint2);

        if (!TextUtils.isEmpty(titileHint2)) {
            mTvTitleHint2.setVisibility(View.VISIBLE);
            mTvTitleHint2.setText(titileHint2);
        } else {
            mTvTitleHint2.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(titileHint)) {
            mTvTitleHint1.setVisibility(View.VISIBLE);
            mTvTitleHint1.setText(titileHint);
        } else {
            mTvTitleHint1.setVisibility(View.GONE);
        }


        if (!TextUtils.isEmpty(title)) {
            mTitleView.setText(title);
            mLLContent1.setVisibility(View.VISIBLE);
        } else {
            mLLContent1.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(content)) {
            mContentView.setText(content);
            mLLContent.setVisibility(View.VISIBLE);
        } else {
            mLLContent.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(content1)) {
            mLLContent1.setVisibility(View.VISIBLE);
            mContentView1.setText(content1);
        } else {
            mLLContent1.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(congtent2)) {
            mContentView2.setVisibility(View.VISIBLE);
        } else {
            mContentView2.setVisibility(View.GONE);
        }

        mOkButton = (TextView) findViewById(R.id.tv_dialog_tip_sure);
        mCancelButton = (TextView) findViewById(R.id.tv_dialog_tip_cancle);

        if (!TextUtils.isEmpty(leftBtnText)) {
            mOkButton.setText(leftBtnText);
        }

        if (!TextUtils.isEmpty(rightBtnText)) {
            mCancelButton.setText(rightBtnText);
        }

        mCancelButton = (TextView) findViewById(R.id.tv_dialog_tip_cancle);
        //mBtnLineView = findViewById(R.id.v_btn_line);

        mOkButton.setOnClickListener(this);
        mCancelButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_dialog_tip_sure:
                mListener.doEnter();
                break;
            case R.id.tv_dialog_tip_cancle:
                dismiss();
                mListener.doCancel();
                break;
            case R.id.tv_dialog_tip_confirm:
                mListener.doEnter();
                break;
            default:
                break;
        }
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setTitileHint(String titileHint) {
        this.titileHint = titileHint;
    }

    public void setTitileHint2(String titileHint) {
        this.titileHint2 = titileHint;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setContent1(String content) {
        this.content1 = content;
    }

    public void setContent2(String content) {
        this.congtent2 = content;
    }

    public void setLeftBtnText(String leftBtnText) {
        this.leftBtnText = leftBtnText;
    }

    public void setRightBtnText(String rightBtnText) {
        this.rightBtnText = rightBtnText;
    }

    public void setOnDialogTipsClickListener(OnDialogTipsClickListener listener) {
        mListener = listener;
    }

    public interface OnDialogTipsClickListener {
        void doEnter();

        void doCancel();
    }

    public static Dialog SignleButtonDialog(Activity context, String info, View.OnClickListener onClickListener) {
        final Dialog dialog = new Dialog(context, R.style.updateDialog);
        View view = View.inflate(context, R.layout.dialog_signle_button,
                null);
        TextView button = (TextView) view.findViewById(R.id.tv_dialog_tip_cancle);

        TextView tv = (TextView) view.findViewById(R.id.tv_dialog_tip_title_hint1);

        tv.setText(info);
        Window window = dialog.getWindow();
        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.6); // 改变的是dialog框在屏幕中的位置而不是大小
        p.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.65
        window.setAttributes(p);
        dialog.setContentView(view);
        dialog.setCancelable(false);


        button.setOnClickListener(onClickListener);
        return dialog;
    }

    public static Dialog memberShowServiceDialog(Activity context, String info, View.OnClickListener onClickListener) {
        final Dialog dialog = new Dialog(context, R.style.updateDialog);
        View view = View.inflate(context, R.layout.dialog_member_service_button,
                null);
        TextView button = (TextView) view.findViewById(R.id.tv_dialog_tip_cancle);

        TextView tv = (TextView) view.findViewById(R.id.tv_dialog_tip_title_hint1);

        tv.setText(info);
        Window window = dialog.getWindow();
        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.6); // 改变的是dialog框在屏幕中的位置而不是大小
        p.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.65
        window.setAttributes(p);
        dialog.setContentView(view);
        dialog.setCancelable(false);


        button.setOnClickListener(onClickListener);
        return dialog;
    }

    public static Dialog withdrawCshDialog(Activity context, String info, String info1, String info2, View.OnClickListener onCancleListener,View.OnClickListener onConfirmListener) {
        final Dialog dialog = new Dialog(context, R.style.updateDialog);
        View view = View.inflate(context, R.layout.dialog_withdraw_csh,
                null);
        TextView button = (TextView) view.findViewById(R.id.tv_dialog_tip_cancle);
        TextView button1 = (TextView) view.findViewById(R.id.tv_dialog_tip_confirm);

        TextView tv = (TextView) view.findViewById(R.id.tv_dialog_tip_title_hint1);
        TextView tv1 = (TextView) view.findViewById(R.id.tv_dialog_tip_content2);
        TextView tv2 = (TextView) view.findViewById(R.id.tv_dialog_tip_content3);

        tv.setText(info);
        tv1.setText(info1);
        tv2.setText(info2);
        Window window = dialog.getWindow();
        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.6); // 改变的是dialog框在屏幕中的位置而不是大小
        p.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.65
        window.setAttributes(p);
        dialog.setContentView(view);
        dialog.setCancelable(false);


        button.setOnClickListener(onCancleListener);
        button1.setOnClickListener(onConfirmListener);
        return dialog;
    }


}
